/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dio.com.model;

import dio.com.model.bean.PCusto;
import dio.com.model.bean.PVenda;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;

/**
 *
 * @author Diogenes
 */
public class Calculos {

    public BigDecimal calcularPrecoDeCustoReal(PCusto pCusto) {
        return pCusto.getPrecoUnitario().
                subtract(pCusto.getDesconto()).
                add(pCusto.getIPI()).
                subtract(pCusto.getICMS()).
                add(pCusto.getFrete()).
                subtract(pCusto.getICMS_SEM_FRETE()).setScale(4, RoundingMode.HALF_DOWN);
    }

    public BigDecimal calcularPrecoDeVenda(PVenda pVenda) {
        BigDecimal soma = new BigDecimal(BigInteger.ONE);
        soma = soma.subtract(pVenda.getPis());
        soma = soma.subtract(pVenda.getConfis());
        soma = soma.subtract(pVenda.getDespesasFinanceirasCartaoDeCredito());
        soma = soma.subtract(pVenda.getIcms_vendas());
        soma = soma.subtract(pVenda.getContribuicaoSocialSemLucro());
        soma = soma.subtract(pVenda.getImpostoRendaSemLucro());
        soma = soma.subtract(pVenda.getAdicionalIRPJ());
        soma = soma.subtract(pVenda.getComissaoSemVendas());
        soma = soma.subtract(pVenda.getPerdaEstoque());
        soma = soma.subtract(pVenda.getDespesasOperacionais());
        soma = soma.subtract(pVenda.getLucro());
        //System.out.print(pVenda.getpCusto().getPrecoDeCusto().divide(soma));
        pVenda.setPrecoVenda(pVenda.getpCusto().getPrecoDeCusto().divide(soma, 4, RoundingMode.HALF_UP));
        return pVenda.getPrecoVenda();
    }
}
